﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using Alos.Common;
using Alos.Entity;
using Alos.IRepository;
using System.Threading.Tasks;
using System.Data;

namespace Alos.LanClass.Api
{
    public class TaskController : ApiController
    {
        IReTaskRepository retaskservice;

        /// <summary>
        /// 构造函数
        /// </summary>
        public TaskController(IReTaskRepository _IReTask)
        {
            retaskservice = _IReTask;
        }
        /// <summary>
        /// 添加发布记录(点击推送)
        /// <param name="reArrangeRecord"></param>
        /// <returns></returns>
        /// </summary>
        [HttpGet]
        [Route("api/Task/GetTaskByResourceID")]
        public JsonRtn<dynamic> StartReArrangeRecord(string ResourceID)
        {
            var jsRtn = new JsonRtn<dynamic>();
            var data = new List<object>();
            DataSet dtSet = retaskservice.GetReTaskByResourceId(Convert.ToInt32(ResourceID));
            data.Add(dtSet.Tables[0].Rows[0]["TaskRequire"].ToString());
            data.Add(dtSet.Tables[0].Rows[0]["TaskGuide"].ToString());
            data.Add(ResourceID);

            List<int> sessionData = (DataHelper.GetObjBySession("zuheid")) as List<int>;
            if (sessionData != null && sessionData.Count != 0)
            {
                data.Add(sessionData[0]);

                sessionData.RemoveAt(0);
                data.Add(sessionData.Count);

                DataHelper.SetSession("zuheid", sessionData);

            }
            else
            {
                DataTable zuheDT = retaskservice.GetTaskZuHe(Convert.ToInt32(ResourceID)).Tables[1];
                List<int> zuheIDList = new List<int>();
                foreach (DataRow row in zuheDT.Rows)
                {
                    zuheIDList.Add(Convert.ToInt32(row["ResourceID"]));
                }
                data.Add(zuheIDList[0]);
                zuheIDList.RemoveAt(0);
                data.Add(zuheIDList.Count);
                DataHelper.SetSession("zuheid", zuheIDList);
            }
            jsRtn.data = data;
            return jsRtn;
        }
    }
}